class ConfigurationClassParser
extends java.lang.Object
Configuration
class definition, populating a collection of
ConfigurationClass
objects (parsing a single Configuration class may result in
any number of ConfigurationClass objects because one Configuration class may import
another using the Import
annotation).
This class helps separate the concern of parsing the structure of a Configuration class from the concern of registering BeanDefinition objects based on the content of that model.
This ASM-based implementation avoids reflection and eager class loading in order to interoperate effectively with lazy class loading in a Spring ApplicationContext.
ConfigurationClassBeanDefinitionReader
Modifier and Type | Class and Description |
---|---|
private static class |
ConfigurationClassParser.CircularImportProblem
|
(package private) static interface |
ConfigurationClassParser.ImportRegistry |
private static class |
ConfigurationClassParser.ImportStack |
Modifier and Type | Field and Description |
---|---|
private ComponentScanAnnotationParser |
componentScanParser |
private java.util.Set<ConfigurationClass> |
configurationClasses |
private Environment |
environment |
private ConfigurationClassParser.ImportStack |
importStack |
private java.util.Map<java.lang.String,ConfigurationClass> |
knownSuperclasses |
private MetadataReaderFactory |
metadataReaderFactory |
private ProblemReporter |
problemReporter |
private java.util.Stack<PropertySource<?>> |
propertySources |
private BeanDefinitionRegistry |
registry |
private ResourceLoader |
resourceLoader |
Constructor and Description |
---|
ConfigurationClassParser(MetadataReaderFactory metadataReaderFactory,
ProblemReporter problemReporter,
Environment environment,
ResourceLoader resourceLoader,
BeanNameGenerator componentScanBeanNameGenerator,
BeanDefinitionRegistry registry)
Create a new
ConfigurationClassParser instance that will be used
to populate the set of configuration classes. |
Modifier and Type | Method and Description |
---|---|
private boolean |
checkAssignability(java.lang.Class<?> clazz,
java.lang.Object candidate) |
private void |
collectImports(AnnotationMetadata metadata,
java.util.Set<java.lang.Object> imports,
java.util.Set<java.lang.String> visited)
Recursively collect all declared
@Import values. |
protected AnnotationMetadata |
doProcessConfigurationClass(ConfigurationClass configClass,
AnnotationMetadata metadata) |
java.util.Set<ConfigurationClass> |
getConfigurationClasses() |
(package private) ConfigurationClassParser.ImportRegistry |
getImportRegistry() |
java.util.Stack<PropertySource<?>> |
getPropertySources() |
private void |
invokeAwareMethods(ImportBeanDefinitionRegistrar registrar)
Invoke
EnvironmentAware , ResourceLoaderAware , BeanClassLoaderAware
and BeanFactoryAware contracts if implemented by the given registrar . |
void |
parse(java.lang.Class<?> clazz,
java.lang.String beanName)
Parse the specified
@Configuration class. |
void |
parse(java.lang.String className,
java.lang.String beanName)
Parse the specified
@Configuration class. |
protected void |
processConfigurationClass(ConfigurationClass configClass) |
private void |
processImport(ConfigurationClass configClass,
AnnotationMetadata metadata,
java.util.Collection<?> classesToImport,
boolean checkForCircularImports) |
private void |
processMemberClasses(AnnotationMetadata metadata)
Register member (nested) classes that happen to be configuration classes themselves.
|
private void |
processPropertySource(AnnotationAttributes propertySource)
Process the given
@PropertySource annotation metadata. |
void |
validate()
Validate each
ConfigurationClass object. |
private final MetadataReaderFactory metadataReaderFactory
private final ProblemReporter problemReporter
private final Environment environment
private final ResourceLoader resourceLoader
private final BeanDefinitionRegistry registry
private final ComponentScanAnnotationParser componentScanParser
private final java.util.Set<ConfigurationClass> configurationClasses
private final java.util.Map<java.lang.String,ConfigurationClass> knownSuperclasses
private final java.util.Stack<PropertySource<?>> propertySources
private final ConfigurationClassParser.ImportStack importStack
public ConfigurationClassParser(MetadataReaderFactory metadataReaderFactory, ProblemReporter problemReporter, Environment environment, ResourceLoader resourceLoader, BeanNameGenerator componentScanBeanNameGenerator, BeanDefinitionRegistry registry)
ConfigurationClassParser
instance that will be used
to populate the set of configuration classes.public void parse(java.lang.String className, java.lang.String beanName) throws java.io.IOException
@Configuration
class.className
- the name of the class to parsebeanName
- may be null, but if populated represents the bean id
(assumes that this configuration class was configured via XML)java.io.IOException
public void parse(java.lang.Class<?> clazz, java.lang.String beanName) throws java.io.IOException
@Configuration
class.clazz
- the Class to parsebeanName
- must not be null (as of Spring 3.1.1)java.io.IOException
protected void processConfigurationClass(ConfigurationClass configClass) throws java.io.IOException
java.io.IOException
protected AnnotationMetadata doProcessConfigurationClass(ConfigurationClass configClass, AnnotationMetadata metadata) throws java.io.IOException
null
if none found or previously processedjava.io.IOException
private void processMemberClasses(AnnotationMetadata metadata) throws java.io.IOException
metadata
- the metadata representation of the containing classjava.io.IOException
- if there is any problem reading metadata from a member classprivate void processPropertySource(AnnotationAttributes propertySource) throws java.io.IOException
@PropertySource
annotation metadata.propertySource
- metadata for the @PropertySource
annotation foundjava.io.IOException
- if loading a property source failedprivate void collectImports(AnnotationMetadata metadata, java.util.Set<java.lang.Object> imports, java.util.Set<java.lang.String> visited) throws java.io.IOException
@Import
values. Unlike most
meta-annotations it is valid to have several @Import
s declared with
different values, the usual process or returning values from the first
meta-annotation on a class is not sufficient.
For example, it is common for a @Configuration
class to declare direct
@Import
s in addition to meta-imports originating from an @Enable
annotation.
metadata
- the metadata representation of the class to searchimports
- the imports collected so farvisited
- used to track visited classes to prevent infinite recursionjava.io.IOException
- if there is any problem reading metadata from the named classprivate void processImport(ConfigurationClass configClass, AnnotationMetadata metadata, java.util.Collection<?> classesToImport, boolean checkForCircularImports) throws java.io.IOException
java.io.IOException
private boolean checkAssignability(java.lang.Class<?> clazz, java.lang.Object candidate) throws java.io.IOException
java.io.IOException
private void invokeAwareMethods(ImportBeanDefinitionRegistrar registrar)
EnvironmentAware
, ResourceLoaderAware
, BeanClassLoaderAware
and BeanFactoryAware
contracts if implemented by the given registrar
.public void validate()
ConfigurationClass
object.public java.util.Set<ConfigurationClass> getConfigurationClasses()
public java.util.Stack<PropertySource<?>> getPropertySources()
ConfigurationClassParser.ImportRegistry getImportRegistry()